package com.grudesign.stutrip.controller;


import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.TriplinePo;
import com.grudesign.stutrip.service.TriplineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 研学线路表 前端控制器
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/tripline")
public class TriplineController {

    @Autowired
    private TriplineService triplineService;

    @PostMapping("/getTripLine/{cur}/{li}")
    public Object getTrip(@PathVariable String cur,
                             @PathVariable String li){
        Object obj =  triplineService.getTrips(cur,li);
        return obj;
    }


    @PostMapping("/getTripLines/{cur}/{li}")
    public Object getQueryTrip(@PathVariable String cur,
                          @PathVariable String li,
                            @RequestBody(required = false) TriplinePo po){
        Object obj =  triplineService.getQuryTrips(cur,li,po);
        return obj;
    }


    @PostMapping("/addTripLine")
    public Object addTrip(@RequestBody TriplinePo tripPo){
        boolean save = triplineService.save(tripPo);
        return save?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }

    @PutMapping("/editNews")
    public Object editTrip(@RequestBody TriplinePo tripPo){
        boolean edit = triplineService.updateById(tripPo);
        return edit?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }
    @DeleteMapping("/{id}")
    public  Object delTrip(@PathVariable String id){
        boolean isDel = triplineService.removeById(id);
        return isDel?new ReturnInfo("200","ok"):new ReturnInfo("-1","err");
    }
}

